package com.astrocsr.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.astrocsr.domain.bean.TblUserGroup;

@Repository("userGroupDAO")
public class UserGroupDAO extends BaseHelperDAO {

	@SuppressWarnings("unchecked")
	public List<TblUserGroup> listUserGroupByEmail(String email) throws Exception {
		List<TblUserGroup> result = null;
		
		String queryString = "from TblUserGroup where email = :email"; // Hibernate Query Language
		result = getCurrentSession().createQuery(queryString).setParameter("email", email).list();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public List<TblUserGroup> listUserGroupByGroupCode(String groupCode) throws Exception {
		List<TblUserGroup> result = null;
		
		String queryString = "from TblUserGroup where groupCode = :groupCode"; // Hibernate Query Language
		result = getCurrentSession().createQuery(queryString).setParameter("groupCode", groupCode).list();
		
		return result;
	}
	
	/**
	 * Insert customer into database
	 */
	public void addUser(TblUserGroup entity) throws Exception {
		// Insert into database
		getCurrentSession().save(entity);
	}
}